# -*- coding: utf-8 -*-
'''
Created on 23 nov. 2010

@author: thierry
'''

import os.path
import random
from optparse import OptionParser

import logging

import core

LEVELS = {'debug': logging.DEBUG,
          'info': logging.INFO,
          'warning': logging.WARNING,
          'error': logging.ERROR,
          'critical': logging.CRITICAL}



def run():
    usage = "%prog -u <user> -p <password> [-l <log level>]"
    str_version = "%prog 0.1"
    parser = OptionParser(usage=usage, version=str_version)
    parser.add_option("-u", "--user", action="store", type="string", dest="user", help="google user")
    parser.add_option("-p", "--password", action="store", type="string", dest="password", help="pasword")
    parser.add_option("-l", "--log", action="store", type="string", dest="level_name", help="log level")
    parser.add_option("-f", "--fullSync", action="store_true", dest="fullSync", default=False, help="proceed to a full sync")

    options, args = parser.parse_args()

    level = LEVELS.get(options.level_name, logging.NOTSET)
    logging.basicConfig(level=level)
    
    logging.info("Nookle N900 <--> Google contact sync")
    logging.info("====================================")
    logging.info("Connecting to google account...")
    ga = core.GoogleAccount(options.user, options.password)
    logging.info("connection successful")
    ga.synchronize(fullSync=options.fullSync)

if __name__ == '__main__':
    run()

    
